home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / PNL Libraries / MyOOAbout.p < prev    next >
Encoding:
Text File  |  1995-10-25  |  4.2 KB  |  206 lines  |  [TEXT/CWIE]

  1. unit MyOOAbout;
  2.  
  3. interface
  4.  
  5.     uses
  6.         MyOOMainLoop;
  7.  
  8.     const
  9.         agwtAbout = '•About';
  10.         about_dialog_ID = 128;
  11.  
  12.     type
  13.         AboutObject = object(DObject)
  14.                 procedure Create (id: integer);
  15.                 override;
  16.                 procedure DoItem (item: integer);
  17.                 override;
  18.                 function GetString (index: integer): str255;
  19.             end;
  20.  
  21.     var
  22.         about_click_count: longInt;
  23.  
  24.     procedure StartupAbout;
  25.     procedure ConfigureAbout (obj: AboutObject);
  26.     procedure UpdateAboutBox;
  27.     procedure OpenAboutBox;
  28.     procedure CloseAboutBox;
  29.  
  30. implementation
  31.  
  32.     uses
  33.         Memory, Fonts, TextEdit, Resources, Icons,
  34.         MyMenus, MyDialogs, MyStrings, MyVersionResource, MySystemGlobals, MyWindows, MyAssertions,
  35.         MyFMenus, AERegistry, MyAEUtils, AEObjects, MyStrh, MyUtils, MyTypes, MyStartup, MyOOMenus, 
  36.         BaseGlobals;
  37.  
  38.     const
  39.         about_strh_id = 928;
  40.  
  41.     var
  42.         about_object: AboutObject;
  43.         gAboutDisplayStyledStringProc : UniversalProcPtr;
  44.  
  45.     procedure AboutObject.DoItem (item: integer);
  46.         var
  47.             r: rect;
  48.     begin
  49.         about_click_count := about_click_count + 1;
  50.         GetDItemRect(window, item, r);
  51.         SetPort(window);
  52.         InvalRect(r);
  53.     end;
  54.  
  55.     function AboutObject.GetString (index: integer): str255;
  56.         var
  57.             vers: versionRecord;
  58.     begin
  59.         GetVersion(vers);
  60.         case index of
  61.             0: 
  62.                 GetString := vers.longVersion;
  63.             1: 
  64.                 GetString := vers.shortVersion;
  65.             2: 
  66.                 GetString := vers.name;
  67.             otherwise
  68.                 GetString := '???';
  69.         end;
  70.     end;
  71.  
  72.     procedure AboutDisplayStyledString (dlg: dialogPtr; item: integer);
  73.         var
  74.             s, t: str255;
  75.             i, n: integer;
  76.     begin
  77.         GetIndString(s, about_strh_id, item);
  78.         i := 1;
  79.         while (i < length(s)) do begin
  80.             if s[i] = '^' then begin
  81.                 n := ord(s[i+1])-48;
  82.                 if n>= 10 then begin
  83.                     n := n-7;
  84.                 end;
  85.                 t := about_object.GetString(n);
  86.                 Delete(s, i, 2);
  87.                 Insert(t, s, i);
  88.                 i := i + length(t);
  89.             end
  90.             else begin
  91.                 i := i + 1;
  92.             end;
  93.         end;
  94.         DisplayStyledString(dlg, item, s);
  95.     end;
  96.  
  97.     procedure AboutObject.Create (id: integer);
  98.         var
  99.             s: str255;
  100.             vers: versionRecord;
  101.             i:integer;
  102.     begin
  103.         UseResFile(app_resfile);
  104.         inherited Create(id);
  105.         SetPort(window);
  106.         close_hides_window := true;
  107.         AppleGuideWindowType := agwtAbout;
  108.         about_click_count := 0;
  109.         gAboutDisplayStyledStringProc := NewUserItemProc(@AboutDisplayStyledString);
  110.         SetMyFont(MFT_Geneva12);
  111.         GetWTitle(window, s);
  112.         GetVersion(vers);
  113.         SPrintS3(s, s, vers.name, '', '');
  114.         SetWTitle(window, s);
  115.         for i := 1 to 30 do begin
  116.             if GetIndStr(about_strh_id, i) <> '' then begin
  117.                 SetDItemHandle(window, i, gAboutDisplayStyledStringProc);
  118.             end;
  119.         end;
  120.     end;
  121.  
  122.     procedure DoAbout;
  123.     begin
  124.         about_click_count := about_click_count + 1;
  125.         if GetWindowVisible(about_object.window) then begin
  126.             if FrontWindow <> about_object.window then begin
  127.                 SelectWindow(about_object.window);
  128.             end;
  129.         end else begin
  130.             SelectWindow(about_object.window);
  131.             ShowWindow(about_object.window);
  132.         end;
  133.     end;
  134.  
  135.     procedure DoAboutMenu;
  136.     begin
  137.         if has_AppleEvents then begin
  138.             SendSelfSimpleEvent(kAECoreSuite, kAEAbout);
  139.         end
  140.         else begin
  141.             DoAbout;
  142.         end;
  143.     end;
  144.  
  145.     procedure SetAboutMenu (themenu, theitem: integer);
  146.     begin
  147.         SetIDItemEnable(themenu, theitem, not ISWObjectFront(about_object));
  148.     end;
  149.  
  150.     function HandleAbout (var event, reply: AppleEvent; refcon: longInt): OSErr;
  151.     begin
  152.         event:=event; { UNUSED! }
  153.         reply:=reply; { UNUSED! }
  154.         refcon:=refcon; { UNUSED! }
  155.         DoAbout;
  156.         HandleAbout := noErr;
  157.     end;
  158.  
  159.     procedure UpdateAboutBox;
  160.     begin
  161.         SetPort(about_object.window);
  162.         InvalRect(about_object.window^.portRect);
  163.     end;
  164.  
  165.     procedure CloseAboutBox;
  166.     begin
  167.         about_object.DoClose;
  168.     end;
  169.  
  170.     procedure OpenAboutBox;
  171.     begin
  172.         DoAbout;
  173.         SetPort(about_object.window);
  174.         DrawDialog(about_object.window);
  175.         ValidRect(about_object.window^.portRect);
  176.     end;
  177.  
  178.     function InitAbout(var msg: integer): OSStatus;
  179.         var
  180.             junk: OSErr;
  181.     begin
  182.         msg := msg; { Unused }
  183.         if has_AppleEvents then begin
  184.             junk := AEInstallEventHandler(kAECoreSuite, kAEAbout, NewAEEventHandlerProc(@HandleAbout), 0, false);
  185.         end;
  186.         SetFBoth(Cabout, DoAboutMenu, SetAboutMenu);
  187.         InitAbout := noErr;
  188.     end;
  189.  
  190.     procedure ConfigureAbout (obj: AboutObject);
  191.     begin
  192.         Assert(obj <> nil);
  193.         about_object := obj;
  194.     end;
  195.     
  196.     procedure StartupAbout;
  197.     begin
  198.         StartupDialogs;
  199.         StartupFMenus;
  200.         StartupMainLoop;
  201.         StartupOOMenus;
  202.         SetStartup(InitAbout, nil, 0, nil);
  203.     end;
  204.     
  205. end.
  206.